package com.kunlong.web.controller;


import app.support.query.PageResult;
import com.kunlong.demo.domain.ShopModel;
import com.kunlong.demo.service.ShopModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 企业
 * 
 * @author leijmdas
 *
 */
@RequestMapping("/shop")
@Controller
public class ShopController {

	@Autowired
	private ShopModelService service;

	@RequestMapping(value = "query", method = RequestMethod.POST)
	public @ResponseBody
	PageResult<ShopModel> query(@RequestBody ShopModel.QueryParam qp) {
		if (qp.getParam() == null) {
			qp.setParam(new ShopModel());
		}
		PageResult<ShopModel> result = new PageResult<ShopModel>();
		result.setData(service.findByQueryParam(qp));
		result.setTotal(service.countByQueryParam(qp));
		return result;
	}


	/**
	 * 保存
	 *
	 * @param entity
	 * @return
	 */
	@RequestMapping(value = "save", method = RequestMethod.POST)
	public @ResponseBody
    Integer save(@RequestBody ShopModel entity) {
		if(entity.getShopId()==null){
			service.save(entity);
			return  entity.getShopId();
		}
		service.updateNotNullPropsById(entity);
		return entity.getShopId();
	}
	@RequestMapping(value = "findById/{id}", method = RequestMethod.GET)
	public @ResponseBody
	ShopModel findById(@PathVariable("id") Integer id) {
		return this.service.findById(id);

	}
	@RequestMapping(value = "deleteById/{id}", method = RequestMethod.GET)
	public @ResponseBody
    Boolean deleteById(@PathVariable("id") Integer id) {
		this.service.deleteById(id);
		return true;
	}




}
